import React from "react"
import { Select} from "antd";
const Option = Select.Option;
export default {
    //封装时间格式化
    formateDate(time){
        if(!time) return ''; 
        let date = new Date(time);
        return date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate() + '  ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
    },
    // 封装分页
    pagination(data,callback){
        return {
            onChange:(current)=>{
                callback(current)
            },
            //result page page_size total是传递过来的数据的名字
            current:data.result.page, 
            pageSize:data.result.page_size,
            total:data.result.total_count,
            showTotal:()=>{
                return `一共${data.result.total_count}条`
            },
            showQuickJumper:true
        }
    },
    //封装表单获取数据
    getOptionList(data){
        if(!data){
            return [];
        }
        let options = [] //[<Option value="0" key="all_key">全部</Option>]//这是默认第一条
        data.map((item)=>{
            options.push(<Option value={item.id} key={item.id}>{item.name}</Option>)
        })
        return options;
    }
}